package com.demo.commons.enums;

public enum ResultEnum implements IResult {
    SUCCESS(2001, "OK"),

    VALIDATE_FAILED(2002, "Validate Failed"),
    COMMON_FAILED(2003, "Common Failed"),
    CREATED(2004, "Created"),
    Not_CONTENT(2005, "No Content"),

    BAD_REQUEST(400, "Bad Request"),
    UNAUTHORIZED(401, "Unauthorized"),
    FORBIDDEN(403, "Forbidden"),
    NOT_FOUND(404, "Not found"),
    NOT_ACCEPTABLE(406, "Not Acceptable"),

    INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
    SERVICE_UNAVAILABLE(503, "Service Unavailable");

    private Integer statusCode;
    private String message;

    public void setStatusCode(Integer statusCode) {
        this.statusCode = statusCode;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    ResultEnum() {

    }

    ResultEnum(int statusCode, String message) {
        this.statusCode = statusCode;
        this.message = message;
    }

    public static ResultEnum fromStatusCode(int statusCode) {
        ResultEnum[] arr = values();
        int length = arr.length;

        for (int i = 0; i < length; i++) {
            ResultEnum resultEnum = arr[i];

            if (resultEnum.getStatusCode() == statusCode) {
                return resultEnum;
            }
        }

        return null;
    }

    @Override
    public Integer getStatusCode() {
        return this.statusCode;
    }

    @Override
    public String getMessage() {
        return this.message;
    }
}
